package com.dianrui.firemenmonitor.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dianrui.firemenmonitor.R;
import com.dianrui.firemenmonitor.bean.Alerm;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class AlarmPromptAdater extends BaseAdapter {

    private List<Alerm> alermList;
    private Context context;


    public AlarmPromptAdater(Context context, List<Alerm> alermList) {
        this.context = context;
        this.alermList = alermList;
    }

    public void refresh(List<Alerm> list) {
        this.alermList = list;
        this.notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return alermList.size();
    }

    @Override
    public Object getItem(int position) {
        return alermList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_alarmprompt, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        if (alermList != null && alermList.size()>0) {
            Alerm alerm = alermList.get(position);
            holder.inputtime.setText(alerm.inputtime);
        }

        return convertView;
    }

     class ViewHolder {
        @BindView(R.id.inputtime)
        TextView inputtime;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
